<?php
namespace Pay\Controller;


use Common\Model\ShanyouNotifyLogModel;

use Pay\Service\PayService;
use Plugins\shanyou\lib;
use Service\Log;
use Think\Controller;


class ShanyouNotifyController extends Controller
{

    public  function __construct()
    {
    }
    public  function  index(){
        $param = $_GET;
        $Log = new Log();
        if(!empty($param)){
            
            $param["remake"]="收到奖励回调";
            $Log->witer("ShanyouNotify",$param);
        }
        $ShanyouNotifyLogModel = new ShanyouNotifyLogModel();
        $ShanyouNotifyLogModel->setParam($param);
        include_once  "plugins/shanyou/lib.php";
        $lib = new lib();
        $Validate =$lib ->getValidateSign($param["taskDataRecord"],$param["userId"] ,$param["taskId"], $param["sdkUserId"] ,$param["taskDataMoney"] ,$param["taskDataRewardMoney"] ,$param["notifyCount"]);
        if($Validate==$param['sign']){
            $money =$param["taskDataMoney"]/100;
            $money=sprintf("%.4f", $money);
            //任务完成给用户发奖金
            $PayService = new PayService();
            $PayService->giveOutMoney($param["sdkUserId"],$money,$param["taskId"],$remake="任务完成",$type="renwu");
            $userInfo = D("users")->where(array("user_id"=>$param["sdkUserId"]))->find();
            $before_money = $userInfo["user_money"];
            /* 插入帐户变动记录 */
            $account_log = array(
                'user_id'       => $param["sdkUserId"],
                'user_money'    => $money,
                'pay_points'    => 0,
                'change_time'   => time(),
                'desc'   =>"任务完成",
                'order_id'   => $param["taskId"],
                "before_money"=>$before_money,
                "later_money"=>$before_money+$money
            );
            M('account_log')->add($account_log);
            $param["remake"]="任务完成奖励成功发放，奖励金额为".$money;
            $Log->witer("ShanyouNotify",$param);
            echo json_encode(array("code"=>1,"message"=>"接收成功"),true);  exit();
        }
        echo  json_encode(array("code"=>0,"message"=>"接收失败"),true);
        exit();
    }
    //http://ad.huijie.cloud/ShanyouNotify/index?recordId=26&sdkChannel=26&userId=311231&taskId=84&sdkUserId=1&taskDataRecord=922&taskDataMoney=90&sdkRewardMoney=90&taskDataRewardMoney=180&notifyCount=3&sign=4b9214b39496185e6388001cf1012cbb&notifyTime=2021-06-04 17:47:11&projectName=1&ratio=1&unit=元








}